<?php
	
	require_once('../inc/fen_fns.php');
	
	sec_session_start();
	
	$publication_id = $_POST['publication_id'];
	$confirmation = $_POST['confirmation'];
	
	$query = $_DB->Query("SELECT fen_members.name, fen_members.surname, fen_members.titr, fen_faculty.faculty_name, fen_department.department_name FROM fen_members, fen_faculty, fen_department where fen_members.username = '".$_SESSION['username']."' and fen_members.faculty_id = fen_faculty.id and fen_members.department_id = fen_department.id");
	$fullname = $_DB->GetResultValue($query, "0", "name")." ".$_DB->GetResultValue($query, "0", "surname");
	
	function GetIP() {
		if(getenv("HTTP_CLIENT_IP")) {
			$ip = getenv("HTTP_CLIENT_IP");
		} elseif(getenv("HTTP_X_FORWARDED_FOR")) {
			$ip = getenv("HTTP_X_FORWARDED_FOR");
			if (strstr($ip, ',')) {
				$tmp = explode (',', $ip);
				$ip = trim($tmp[0]);
			}
		} else {
			$ip = getenv("REMOTE_ADDR");
		}
		return $ip;
	}
	$ip = GetIP();
	
	$pidquery = $_DB->Query("SELECT fen_publication_app.publication_id from fen_publication_app where id = '".$publication_id."'");
	//echo $_DB->GetResultValue($pidquery, "0", "publication_id");
	
	if(login_check($mysqli, '=', '100') == true) {
	
		
		if ($confirmation == '1') {
			
			$query = $_DB->Query("update fen_publication_app
					SET
					status = '4', cancel_reason = '', modified_by = '".$_SESSION['username']."', date_modified = DATE_ADD(CURRENT_TIMESTAMP, INTERVAL 3 HOUR) 
					WHERE id = '$publication_id'
					");
			
			$query1 = $_DB->Query("insert into fen_transaction_history values
                         (null,
						 '".$_DB->GetResultValue($pidquery, "0", "publication_id")."',
						 '".MALIISLEREGONDERILDI."',
						 '".$ip."',
						 DATE_ADD(CURRENT_TIMESTAMP, INTERVAL 3 HOUR),
		  				 '".$fullname."'
						 )");
			
		} 
		
		header('Location: ../applications.php');
	
	} else {
		header('Location: ../index.php?error=2');
	}

	